<template>
  <div style="width: 600px">
    <el-form ref="form" :rules="rules" label-width="100px">
      <el-form-item label="步骤名称" prop="name">
        <el-input v-model="step.name" placeholder="步骤名称"></el-input>
      </el-form-item>
    <br>
    <el-button type="primary" @click="obtainFields">获取字段</el-button>
    <el-button icon="plus" @click="step.fields.push({name:'',case_insensitive:'Y',edit:true})"></el-button>
    <br><br>
    <el-table :data="step.fields" border stripe style="width: 100%" :max-height="400">
      <el-table-column type="index" width="80"></el-table-column>
      <el-table-column label="字段名称" :width="160">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.name}}</div>
          <div v-else >
            <el-select  v-model="scope.row.name" placeholder="字段名称">
              <el-option v-for="item in step.availableFields" :value="item.name"></el-option>
            </el-select>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="忽略大小写" :width="160">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.case_insensitive}}</div>
          <div v-else >
            <el-select  v-model="scope.row.case_insensitive" placeholder="忽略大小写">
              <el-option   value="Y"></el-option>
              <el-option   value="N"></el-option>
            </el-select>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" :width="140">
        <template scope="scope">
          <el-row>
            <el-col :span="12"><el-button size="small" type="info" @click="scope.row.edit=!scope.row.edit">编辑</el-button></el-col>
            <el-col :span="12"><el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button></el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    </el-form>
  </div>
</template>
<script>
  import {Steps} from "../../model/DataModel";
  import StepCommon from "./mixins/StepMixin";
  export default{
    mixins: [StepCommon],
    data(){
      return {
        msg: 'hello vue',
        step: Steps.Unique()
      }
    },
    methods:{
      obtainFields(){
          let params=this.step.availableFields;
          if(params&&params.length>0){
              this.step.fields=params.map(el=>{return {name:el.name,case_insensitive:"Y",edit:false}})
          }
      }
    }
  }
</script>
